<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>数组的循环渲染</h2>
      <ul>
        <!-- v-for指令就是用来做循环渲染的 -->
        <!-- 只有v-for里面写的是语句 -->

        <!-- forin和forof完全相同，都可以用来做对象和数组的遍历 -->
        <li v-for="item in list">{{ item }}</li>
      </ul>
      <ul>
        <!-- 有item和index两个参数 -->
        <li v-for="(item, index) in list2">
          {{ item.name }} - {{ item.id }} - {{ index }}
        </li>
      </ul>
      <button @click="add">btn</button>

      <hr />

      <h2>对象的循环渲染</h2>
      <ul>
        <!-- 对象也能循环，有三个参数，分别是value,key,index -->
        <li v-for="(value, key, index) in obj">
          {{ value }} - {{ key }} - {{ index }}
        </li>
      </ul>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            list: [1, 2, 3, 4, 5],
            list2: [
              {
                name: "zhangsan",
                id: 1,
              },
              {
                name: "lisi",
                id: 2,
              },
            ],
            obj: {
              name: "wangwu",
              sex: "男",
              address: "九堡",
              phone: "110",
            },
          };
        },
        methods: {
          add() {
            this.list.push(6);
            // this.list = this.list.concat(6);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
